// opencv async detector demo
// Author: lihaoweicv@hotmail.com
// MIT License

#include "detector/demo_detector.h"
#include <thread>

namespace cvf
{
    Status Demo_Detector::init_models(std::vector<std::string> &modelconfigs)
    {
        //我们这里是个空模型，直接返回OK
        return Status_OK;
    }
    Status Demo_Detector::detect_on_frame(cv::Mat &imgBGR, DetInfo &det)
    {
        // 在这里专注来做怎么检测
        // demo 是个很简单的检测是否摄像头遮住是黑的，如果是黑的，就输出个框

        cv::Mat gray;
        cv::cvtColor(imgBGR, gray, cv::COLOR_RGB2GRAY);
        cv::Scalar s = cv::mean(gray);
        const float  THRESH = 20;
        if(s[0] < THRESH)
        {
            det.hasObject = true;
            det.conf = 1.0f;
            det.detBox = cv::Rect(0.1*imgBGR.cols, 0.1*imgBGR.rows,
                                  0.8*imgBGR.cols, 0.8*imgBGR.rows);
        }
        else
        {
            det.hasObject = true;
            det.conf = 0.0f;
        }
        //故意延迟一下
        std::this_thread::sleep_for(std::chrono::milliseconds(200));

        return Status_OK;
    }

}//namespace cvf



